package com.mofeng.myshop.domain.vo.user;

import com.mofeng.myshop.domain.po.UserBase;
import com.mofeng.myshop.domain.po.UserInfo;
import com.mofeng.myshop.domain.po.UserPower;
import com.mofeng.myshop.domain.po.UserRole;
import com.mofeng.myshop.domain.vo.base.BaseVo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class UserVo extends BaseVo {
    @Schema(description = "头像")
    private String imageUrl;
    @Schema(description = "邮箱")
    private String email;
    @Schema(description = "电话")
    private String phone;
    @Schema(description = "状态 1 正常 2 禁用")
    private String state;

    @Schema(description = "是否领取礼包 0 未领取 1 领取")
    private String isGet;

    @Schema(description = "Steam ID")
    private String steamId;

    @Schema(description = "游戏 ID")
    private String gameId;

    @Schema(description = "qq ")
    private String qq;

    @Schema(description = "余额 ")
    private String money;

    @Schema(description = "消费余额 ")
    private String amount;

    @Schema(description = "游戏名 ")
    private String gameName;

    @Schema(description = "性别")
    private String sex;

    @Schema(description = "简介")
    private String introduction;

    @Schema(description = "地址")
    private String address;

    @Schema(description = "密码")
    private String password = null;

    @Schema(description = "邀请码UUID")
    private String invitationCode;

    @Schema(description = "邀请码用户")
    private String invitationUserId;

    //    @Schema(description = "权限等级")
    private int powerNumber;
    private String powerId;
    @Schema(description = "权限名称")
    private String powerName = "无";
    @Schema(description = "角色名称")
    private String roleName = "无";
    private String roleId;
    @Schema(description = "权限折扣")
    private Float discount;

    public UserVo(UserBase user) {
        super(user);
        this.imageUrl = user.getImage();
        this.email = user.getEmail();
        this.phone = user.getPhone();
        this.state = user.getState();
        UserInfo info = user.getInfo();
        if (info != null) {
            this.steamId = info.getSteamId();
            this.gameId = info.getGameId();
            this.qq = info.getQq();
            this.money = info.getMoney();
            this.amount = info.getAmount();
            this.gameName = info.getGameName();
            this.sex = info.getSex();
            this.introduction = info.getIntroduction();
            this.address = info.getAddress();
            this.invitationUserId = info.getInvitationUser() == null ? "" : info.getInvitationUser().toString();
            this.invitationCode = info.getInvitationCode();
            this.isGet = info.getReceiveState();
        }
        UserPower power = user.getPower();
        if (power != null) {
            this.powerNumber = power.getNumber() == null ? 0 : power.getNumber();
            this.powerName = power.getName();
            this.powerId = power.getId() == null ? null : power.getId().toString();
        }
        UserRole role = user.getRole();
        if (role != null) {
            this.roleName = role.getName();
            this.discount = role.getDiscount();
            this.roleId = role.getId() == null ? null : role.getId().toString();
        }
    }

    public static List<UserVo> change(Collection<UserBase> users) {
        if (users == null) {
            return null;
        }
        return users.stream().map(UserVo::new).collect(Collectors.toList());
    }
}
